using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using QLKS.DataLayer.ManagerObjects;
using QLKS.DataLayer.BusinessObjects;
using QLKS.DataLayer.Base;

namespace QLKS.DataLayer.UnitTests
{
	[TestFixture]
    public partial class PhongTests : UNuitTestBase
    {
        protected IPhongManager manager;
		
		public PhongTests()
        {
            manager = managerFactory.GetPhongManager();
        }
		
		protected Phong CreateNewPhong()
		{
			Phong entity = new Phong();
			
			// You may need to maually enter this key if there is a constraint violation.
			entity.Id = "Test Test ";
			
			entity.TenPhong = "Test Test Test Test Test Test Test T";
			entity.GhiChu = "Test Test ";
			entity.TinhTrang = true;
			entity.IsActive = true;
			
			ILoaiPhongManager loaiPhongManager = managerFactory.GetLoaiPhongManager();
			entity.LoaiPhong = loaiPhongManager.GetAll(1)[0];
			
			return entity;
		}
		protected Phong GetFirstPhong()
        {
            IList<Phong> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				Phong entity = CreateNewPhong();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                Phong entityA = CreateNewPhong();
				manager.Save(entityA);

                Phong entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                Phong entityA = GetFirstPhong();
				
				entityA.TenPhong = "Test Test Test Test Test Test T";
				
				manager.Update(entityA);

                Phong entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.TenPhong, entityB.TenPhong);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                Phong entity = GetFirstPhong();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}

